A Semantics of Object Types

نویسندگان

  • Martín Abadi
  • Luca Cardelli
چکیده

We give a semantics for a typed object calculus, an extension of System F with object subsumption and method override. We interpret the calculus in a per model, proving the soundness of both typing and equational rules. This semantics suggests a syntactic translation from our calculus into a simpler calculus with neither subtyping nor objects. 1. Objects, Records, and Functions Despite the many formal accounts of object-oriented languages, the meaning and the properties of object types remain unclear. In particular, the soundness of object subtyping depends on invariants difficult to capture with standard type constructions; attempts based on record types have been inspiring but not compelling. In order to study object types in a clear setting, we give semantics to an extension of Girard’s System F [Girard, Lafont, Taylor 1989] with subtyping, recursion, and some basic object constructs. Like all common object-oriented languages, this calculus supports object subsumption and method override. With subsumption, a new object with more methods can replace an old object transparently. Override is the operation that modifies the behavior of an object, or class, by replacing one of its methods. Neither subsumption nor override is too hard to model in isolation, but their combination has been problematic (see Section 6). Our starting point is the naive view that an object is a record of methods, and that each method is a function. When a method of an object o is invoked, the corresponding function is applied to o. This view of objects as records of functions is often used informally in the literature and it underlies all implementations of standard (single-dispatch) object-oriented languages. In this work, we extend this view to object types. We construct a model based on partial equivalence relations (pers). In our interpretation, objects are records of functions, object types are certain unions of recursive record types, and subtypes are subsets. Along the way, we study unions of pers, and thereby obtain a per semantics for abstract data types and partially abstract data types. We prove the soundness of both typing and equational rules. The per interpretation is direct enough to be informative. In particular, it suggests a syntactic translation from our calculus to a less unconventional extension of System F, with recursion and records, but neither subtyping nor objects. The rest of this introduction describes objects, their intended behavior, and the semantic problems that our approach is designed to solve. Some of this material is borrowed from [Abadi, Cardelli 1994b; Abadi, Cardelli 1994c], where we develop typed and untyped object calculi. We start by describing an untyped calculus that includes object formation, method invocation, and method override. An object is a collection of components [li=ai i Ï1..n], for distinct labels li and associated methods ai. The order of these components does not matter. A method is a function having a special parameter, called self. A proper method makes use of its self parameter; a field is a method that ignores self. The letter ς is used as a binder for self, like a special λ binder; ς(x)b is a method with self parameter x and with body b. The object containing a given method is called the method’s host object. A method invocation (or selection) is written o.lj, where lj is a label of o. It reduces to the result substituting o for the self parameter in the body of the method named lj. Thus, a method can be applied only to its host object; this invariant is essential for typing objects and for reasoning about them. A method override (or update) is written o.ljfiüς(y)b. The intent is to replace the method named lj of o with ς(y)b. Our semantics of override is functional: the result of an override is a copy of the object where the overridden method has been replaced by the new one. This form of method override is more general than usual, in that it applies to objects rather than classes; the generality does not complicate our formal treatment and has advantages in simplicity and expressiveness. We give a direct, informal semantics of objects, viewing them as primitive: Primitive Semantics Let o 7 [li=ς(xi)bi iÏ1..n] (li distinct) o is an object with method names li and methods ς(xi)bi o.lj Òñ bj{xj←o} selection/invocation (jÏ1..n) o.ljfiüς(y)b Òñ [li=ς(xi)bi iÏ(1..n)-{j}, lj=ς(y)b] update/override (jÏ1..n) Notation We write Φi iÏ1..n for a sequence Φ 1,...,Φn . The substitution of c for the free occurrences of x in b is b{x←c}. We use Òñ for “rewrites to”, @ for definitional equality, 7 for syntactic identity, and = for provable equality between terms. We identify terms up to renaming of bound variables. While the primitive semantics reflects the programmer’s view of objects, the implementations of standard object-oriented languages are based on self-application. In the self-application semantics [Kamin 1988], methods are functions, objects are records, invocation is record selection plus self-application, and override is record update. We use the notation Üli=ai iÏ1..ná for the record with labels li and fields ai; r† lj for record selection (extracting the lj component of r); and r†lj:=b for record update (producing a copy of r with the lj component replaced by b). Self-application Semantics For o 7 [li=ς(xi)bi iÏ1..n] (li distinct) o @ Üli=λ(xi)bi iÏ1..ná o.lj @ o†lj(o) = bj{xj←o} (jÏ1..n) o.ljfiüς(y)b @ o†lj:=λ(y)b = [li=ς(xi)bi iÏ(1..n)-{j}, lj=ς(y)b] (jÏ1..n)

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Declarative Semantics in Object-Oriented Software Development - A Taxonomy and Survey

One of the modern paradigms to develop an application is object oriented analysis and design. In this paradigm, there are several objects and each object plays some specific roles in applications. In an application, we must distinguish between procedural semantics and declarative semantics for their implementation in a specific programming language. For the procedural semantics, we can write a ...

متن کامل

Lexical Semantics and Selection of TAM in Bantu Languages: A Case of Semantic Classification of Kiswahili Verbs

The existing literature on Bantu verbal semantics demonstrated that inherent semantic content of verbs pairs directly with the selection of tense, aspect and modality formatives in Bantu languages like Chasu, Lucazi, Lusamia, and Shiyeyi. Thus, the gist of this paper is the articulation of semantic classification of verbs in Kiswahili based on the selection of TAM types. This is because the sem...

متن کامل

Modeling and Evaluation of Stochastic Discrete-Event Systems with RayLang Formalism

In recent years, formal methods have been used as an important tool for performance evaluation and verification of a wide range of systems. In the view points of engineers and practitioners, however, there are still some major difficulties in using formal methods. In this paper, we introduce a new formal modeling language to fill the gaps between object-oriented programming languages (OOPLs) us...

متن کامل

Modeling and Evaluation of Stochastic Discrete-Event Systems with RayLang Formalism

In recent years, formal methods have been used as an important tool for performance evaluation and verification of a wide range of systems. In the view points of engineers and practitioners, however, there are still some major difficulties in using formal methods. In this paper, we introduce a new formal modeling language to fill the gaps between object-oriented programming languages (OOPLs) us...

متن کامل

Recursive Object Types in a Logic of Object-Oriented Programs

This paper formalizes a small object-oriented programming notation. The notation features imperative commands where objects can be shared (aliased), and is rich enough to allow subtypes and recursive object types. The syntax, type checking rules, axiomatic semantics, and operational semantics of the notation are given. A soundness theorem, showing the consistency between the axiomatic and opera...

متن کامل

Recursive Object Types in a Logic Ofobject - Oriented Programsk

This paper formalizes a small object-oriented programming notation. The notation features imperative commands where objects can be shared (aliased), and is rich enough to allow subtypes and recursive object types. The syntax, type checking rules, axiomatic semantics, and operational semantics of the notation are given. A soundness theorem showing the consistency between the axiomatic and operat...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 1994